﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace TerenXNA
{
    class Skybox
    {
        Model skyModel;
        float scale = 40;
        //public float avatarYaw = 0, avatarPitch = 0, avatarRoll = 0;

        public Skybox()
        {
            skyModel = Game1.contentManager.Load<Model>("Models/skyModel");
        }

        public void draw(Matrix projectionMatrix, Matrix viewMatrix, Camera aktCam, float lightDirection)
        {

            //Matrix[] transforms = new Matrix[skyModel.Bones.Count];
            //skyModel.CopyAbsoluteBoneTransformsTo(transforms);

            //RasterizerState rs = new RasterizerState();
            //rs.FillMode = FillMode.Solid;
            //Game1.device.RasterizerState = rs;

            foreach (ModelMesh mesh in skyModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.LightingEnabled = false;
                    effect.AmbientLightColor = new Vector3(1, 1, 1);
                    effect.DiffuseColor = new Vector3(1, 1, 1);

                    effect.View = viewMatrix;
                    effect.Projection = projectionMatrix;
                    Vector3 rot = new Vector3(-MathHelper.PiOver2, 0, MathHelper.Pi - MathHelper.PiOver4);

                    scale = aktCam.coords.farValue / 260;
                    //effect.World = world * Matrix.CreateScale(0.1f) * translateMatrix;
                    effect.World = Matrix.CreateScale(scale, scale, scale * 0.3f) *
                        Matrix.CreateRotationX(-1.45f) *
                        Matrix.CreateRotationZ(lightDirection) *
                        //Matrix.CreateRotationY(avatarYaw) * 
                        Matrix.CreateTranslation(aktCam.coords.obx, aktCam.coords.oby-4500, aktCam.coords.obz);
                }
                mesh.Draw();
            }
        }
    }
}
